package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import dao.BaseDao;
import dao.Mogujie_userDao;
import entity.Mogujie_user;

public class Mogujie_userDaoImpl extends BaseDao implements Mogujie_userDao {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
	@Override
	public List<Mogujie_user> searchAll() {
		
		return null;
	}

	//添加
	@Override
	public int addUser(Mogujie_user mogujie_user) {
		String sql ="INSERT INTO `mogujie`.`mogujie_user` ( `userName`, `password`, `mobile`, `carid`,`sex`) VALUES(?,?,?,?,?) ";
		Object [] params = {
				mogujie_user.getUserName(),
				mogujie_user.getPassword(),
				mogujie_user.getMobile(),
				mogujie_user.getCarid(),
				mogujie_user.getSex()
			};
		int res = super.exceuteUpdate(sql, params);
		return res;
	}

	@Override
	public int updUser(Mogujie_user mogujie_user) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int delUser(Mogujie_user mogujie_user) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Mogujie_user  searchInfo(String userName,String password) {
		ResultSet rSet = null;
		String sql = "SELECT * FROM mogujie_user WHERE mobile	=? AND PASSWORD = ?";
		Object [] param = {userName,password};
		rSet = this.execute(sql, param);
		Mogujie_user mogu = null;
		try {
			while(rSet.next()) {
				mogu = new Mogujie_user();
				mogu.setUserName(rSet.getString("userName"));
				mogu.setImage(rSet.getString("image"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return mogu;
	}

}
